<template>
	<div>
		展示文案
		当前的type：{{type}}
	</div>
</template>

<script>
	// 文案库引进来
	import resultData from "../../resultData.json";
	export default {
		created() {
			let answer = this.getRandAnswer()
			// console.log(answer)
			this.answer = answer
		},
		data(){
			return {
				answer:"",
				// gender:""
			}
		},
		methods:{
			getRandAnswer(){
				// console.log(resultData['type'+this.type])
				// resultData['type'+this.type]
				const sex = this.getSex();
				const obj = resultData['type'+this.type];
				const dataArr = obj[sex];
				// console.log(dataArr)
				// 先判断dataArr的长度
				if(dataArr.length<=1){
					return dataArr[0]
				}else{
					let rand = Math.random()*dataArr.length
					rand = rand | 0;
					return dataArr[rand]
				}
			},
			getSex(){
				let gender = this.gender;
				switch(gender){
					case "1":
						return "boy"
						break;
					case "noface":
						return "other"
						break;
					default:
						return "girl"
						break;
				}
			}
		},
		computed:{
			type(){
				return this.$store.state.type
			},
			gender(){
				return this.$store.state.gender
			}
		}
	}
</script>

<style>
</style>
